<?php
/**
 * Component Bayon
 * 
 * 
 */
class BayonComponent extends Object{
	
/**
 *
 * Include other component
 *
 */
    public $components = array('Session');
    
	private function getUser(){
		if( $this->Session->check('Auth.User') ){
			return $this->Session->read('Auth.User');
		}else{
			return false;
		}
		
	}
/**
 * If Guest
 * 
 */    
	public function isGuest(){
    	if(!$this->Session->read('Auth.User')){
    		return true;
    	}else{
    		return false;
    	}
    	
    }
	
	public function isLogging(){
		if($this->getUser()){
			return true;
		}else{
			return false;
		}
	}
	
	public function username(){
		$user = $this->getUser();
		if( $user ){
			return $user['username'];
		}else{
			return false;
		}
	}
	
	public function userId(){
		$user = $this->getUser();
		if( $user ){
			return $user['id'];
		}else{
			return false;
		}
	}
    
	public function bayonFilter($ret){
		$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
	  	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
	  	$ret = preg_replace("/@(\w+)/", "@<a href=\"http://bayonpage.com/\\1\" target=\"_blank\">\\1</a>", $ret);
	  	$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.bayonpage.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $ret);
		return $ret;
	}
}
?>